home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / tutorials / custEducation / opengl1 / examples / windows / background.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  1.9 KB  |  80 lines

  1. /*
  2.  * Copyright 1993, 1996, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. /* background.c - open a window and clear the background.
  19.  *   glutMainLoop() calls drawScene whenever the window needs
  20.  *   to be updated.
  21.  */
  22. #include <GL/gl.h>
  23. #include <GL/glut.h>
  24.  
  25. /* Function Prototypes */
  26. GLvoid initgfx( GLvoid );
  27. GLvoid drawScene( GLvoid );
  28.  
  29. void checkError( char * );
  30.  
  31. void
  32. main( int argc, char *argv[] )
  33. {
  34.     GLsizei width, height;
  35.  
  36.     glutInit( &argc, argv );
  37.  
  38.     /* create a window that is 1/4 the size of the screen,
  39.      * and position it in the middle of the screen.
  40.      */
  41.     width = glutGet( GLUT_SCREEN_WIDTH ); 
  42.     height = glutGet( GLUT_SCREEN_HEIGHT );
  43.     glutInitWindowPosition( width / 4, height / 4 );
  44.     glutInitWindowSize( width / 2, height / 2 );
  45.     glutInitDisplayMode( GLUT_RGBA );
  46.     glutCreateWindow( argv[0] );
  47.  
  48.     initgfx();
  49.  
  50.     glutDisplayFunc( drawScene ); 
  51.     glutMainLoop();
  52. }
  53.  
  54. GLvoid
  55. initgfx( GLvoid )
  56. {
  57.     /* set clear color to magenta */
  58.     glClearColor( 1.0, 0.0, 1.0, 1.0 );
  59. }
  60.  
  61. void 
  62. checkError( char *label )
  63. {
  64.     GLenum error;
  65.     while ( (error = glGetError()) != GL_NO_ERROR )
  66.         printf( "%s: %s\n", label, gluErrorString(error) );
  67. }
  68.  
  69.  
  70. GLvoid
  71. drawScene( GLvoid )
  72. {
  73.     glClear( GL_COLOR_BUFFER_BIT );
  74.  
  75.     /* Do all your OpenGL rendering here */
  76.  
  77.     checkError( "drawScene" );
  78.     glFlush();
  79. }
  80.